package com.cwm.test.proxy.autocode.client;

import com.cwm.test.proxy.autocode.proxy.GPClassloader;
import com.cwm.test.proxy.autocode.proxy.GPInvocationHandler;
import com.cwm.test.proxy.autocode.proxy.GPProxy;

import java.lang.reflect.Method;

public class GPMeiPo implements GPInvocationHandler {

    private Object target;

    public Object getInstance(Object target) {
        this.target = target;
        Class<?> cls = target.getClass();
        return new GPProxy().newProxyInstance(new GPClassloader(), cls.getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("执行方法前");
        Object result = method.invoke(target, args);
        System.out.println("执行方法后");
        return result;
    }
}


